import axios from '@/request/http'
// @ == src
// import NproGress from 'nprogress'

export default {
    namespaced: true,
    mutations: {
        INIT_LIST(state, { data, flag }) {
            state.list = data
            state.loading = flag
        },
        // 添加
        LIST_ADD_ITEM(state, { item }) {
            state.list.push(item)
        },
        // 删除
        REM_LIST_ITEM(state, { index }) {
            state.list.splice(index, 1)
        },
        // 控制loading
        SET_LOADING(state) {
            state.loading = true
        }
    },
    actions: {
        init({ commit }) {
            axios.get('/getList').then(data => {
                commit("INIT_LIST", {
                    data,
                    flag: false
                })
                // 关闭进度条
                // NproGress.done()
            })
        },
        // 搜索
        search({ commit }, { input }) {
            axios.get('/search', {
                params: {
                    input
                }
            }).then(data => {
                commit("INIT_LIST", {
                    data,
                    flag: false
                })
            })
        }
    },
    state: {
        list: [],
        loading: true
    }
}